package com.perfma.xtest.tool;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author: junhui.si
 * @date: 2021-11-16 10:26
 **/
public class ToJson {

    /**
     * env: select org_id,id, environment_name from environment_info where is_deleted=1;
     * workspace: select org_id,id from product where is_deleted=1;
     *
     *
     * @param args
     */
    public static void main(String[] args) {
        String envStr = "1\t352368089192681472\t测试\n" +
                "349124889728450560\t349128285638295552\ttest_Env\n" +
                "349734217703436288\t383103696743141376\tceshi\n" +
                "349734217703436288\t373028128521674752\ttest\n" +
                "349734217703436288\t383132711050772480\t测试\n" +
                "349734217703436288\t383547116997541888\t辅导费\n" +
                "350479363483062272\t350658499069562880\t测试压测环境";
        String workspaceStr = "0\t349736339954151424\n" +
                "0\t349129761563545600\n" +
                "0\t349129630650929152\n" +
                "349124889728450560\t349141361372639232\n" +
                "349124889728450560\t349132843940773888\n" +
                "349734217703436288\t378500824604835840\n" +
                "349734217703436288\t349797400610811904\n" +
                "349734217703436288\t359172255651164160\n" +
                "349734217703436288\t357446976612298752\n" +
                "349734217703436288\t349803454740508672\n" +
                "349734217703436288\t374077838967660544\n" +
                "349734217703436288\t349798200665911296\n" +
                "349734217703436288\t358859012982398976\n" +
                "350479363483062272\t350656256727531520\n" +
                "350479363483062272\t350657866140696576\n" +
                "350479363483062272\t350662971296534528\n" +
                "350479363483062272\t350663266386792448\n" +
                "350479363483062272\t350665445155749888\n" +
                "375550754263621632\t375829511989846016";

        List<List<String>> envSource = parse(envStr);
        List<List<String>> workspaceSource = parse(workspaceStr);

        List<FillEnvNameForm> envFormList = Lists.newArrayList();
        List<DeleteWorkspaceForm> workspaceFormList = Lists.newArrayList();

        envSource.forEach(s->{
            FillEnvNameForm fillEnvNameForm = FillEnvNameForm.builder()
                    .orgId(Long.parseLong(s.get(0)))
                    .envId(Long.parseLong(s.get(1)))
                    .envName(s.get(2))
                    .build();
            envFormList.add(fillEnvNameForm);
        });
        System.out.println(JSON.toJSONString(envFormList));
        System.out.println("############################################################");

        workspaceSource.forEach(s->{
            DeleteWorkspaceForm deleteWorkspaceForm = DeleteWorkspaceForm.builder()
                    .merchantId(Long.parseLong(s.get(0)))
                    .workspaceId(Long.parseLong(s.get(1)))
                    .build();
            workspaceFormList.add(deleteWorkspaceForm);
        });
        System.out.println(JSON.toJSONString(workspaceFormList));
    }

    public static List<List<String>> parse(String str){
        List<List<String>> resultList = Lists.newArrayList();
        List<String> array = Lists.newArrayList(str.split("\n"));
        for (String item : array){
            List<String> temp = Lists.newArrayList(item.split("\t"));
            resultList.add(temp);
        }
        return resultList;
    }
}
